<template>
  <div ref="scatter" class="scatter-charts"></div>
</template>

<script>
export default {
  name: 'Scatter',
  props: ['Data1', 'Data2', 'title'],
  watch: {
    Data1: {
      handler(val) {
        if (val.length > 0) {
          this.scatterChart()
        }
      },
      deep: true
    },
    Data2: {
      handler(val) {
        if (val.length > 0) {
          this.scatterChart()
        }
      },
      deep: true
    }
  },
  mounted() {
    this.scatterChart()
  },
  methods: {
    scatterChart() {
      let scatter = this.$echarts.init(this.$refs.scatter)
      let datas = []
      for (let i = 0; i < this.Data1.length; i++) {
        let arr = []
        arr.push(this.Data1[i][1])
        arr.push(this.Data1[i][0])
        datas.push(arr)
      }
      console.log(datas)
      let option = {
        title: {
          show: true,
          text: this.title,
          left: '45%',
          top: '6%',
          textStyle: {
            fontSize: '16',
            color: '#ffffff',
            textShadowColor: '#ffffff',
            textShadowBlur: '10',
            textShadowOffsetY: 0,
            textShadowOffsetX: 0
          }
        },
        grid: {
          left: '25%'
        },
        xAxis: {
          min: 0,
          max: 20,
          splitLine: {
            show: false
          },
          axisLine: {
            show: true,
            color: '#000000'
          },
          axisTick: {
            show: false
          }
        },
        yAxis: {
          min: 0,
          max: 20,
          splitLine: {
            show: false
          },
          axisLine: {
            show: true,
            color: '#000000'
          },
          axisTick: {
            show: false
          }
        },
        series: [{
          type: 'scatter',
          data: this.Data1
        },
        {
          type: 'scatter',
          data: datas
        }
        ]
      }
      scatter.setOption(option)
      window.addEventListener('resize', e => {
        scatter.resize()
      })
    }
  }
}
</script>

<style scoped>
  .scatter-charts {
    width: 90%;
    height: 100%;
  }
</style>
